
	** ETHIOPIA: CLEAN WAVE 3
		
	 * prep consumption file 
	 use "$dir/rawdata/LSMS Ethiopia/2015/cons_agg_w3.dta", clear
	 
	 ren nom_totcons_aeq w3_conspc
	 ren hh_size w3_hhsize_fromcons
	 
	 keep household_id2 w3*
	 tempfile consumption
	 save `consumption', replace
	 
	 use "$dir/rawdata/LSMS Ethiopia/2015/Household/sect1_hh_w3.dta", clear // ROSTER
	 merge 1:1 household_id2 individual_id2 using "$dir/rawdata/LSMS Ethiopia/2015/Household/sect3_hh_w3.dta", assert(master matched) nogen // HEALTH
	 merge 1:1 household_id2 individual_id2 using "$dir/rawdata/LSMS Ethiopia/2015/Household/sect4_hh_w3.dta", assert(master matched) nogen // LABOR
	 merge m:1 household_id2 using `consumption', assert(master matched) nogen // CONSUMPTION
	 
	 /*
	 Section 1: Roster
	 Section 2: Education
	 Section 3: Health
	 Section 4: Time use and labor	 
	 Section 5a&b: Food consumption
	 Section 6: Non-food expenditure
	 Section 7: Food security
	 Section 8: Shocks
	 Section 9: Housing
	 Section 10: Assets
	 Section 11: Non-farm enterprise
	 Section 12: Other income
	 Section 13: Assistance
	 Section 14: Credit
	 */
	 
	 ren household_id2 hhid
	 gen indiv=substr(individual_id2,strlen(individual_id2)-1,2)
	 destring indiv, replace
	 assert indiv==hh_s1q00
	 
	 ** INFORMATION FROM HOUSEHOLD ROSTER

		** Still in HH
			gen w3_inhh=hh_s1q04c!=2
		
		** Age
			gen w3_age=hh_s1q04a
			replace w3_age=hh_s1q04h if !missing(hh_s1q04h)
			
		** Household size
			gen temp=1 if w3_inhh==1
			bys hhid: egen w3_hh_size=total(temp)
			drop temp

		** Number of children 12 or younger
			gen temp=1 if w3_age<=12 & w3_inhh==1
			bys hhid: egen w3_hh_under12=total(temp)
			drop temp

		** Number of youth 18 or younger
			gen temp=1 if w3_age<=18 & w3_inhh==1
			bys hhid: egen w3_hh_under18=total(temp)
			drop temp

		** Number of adults 60 or older
			gen temp=1 if w3_age>=60 & !missing(w3_age) & w3_age!=999 & w3_inhh==1
			bys hhid: egen w3_hh_over60=total(temp)
			drop temp

		** Adults 12 to 60
			gen temp=1 if w3_age>12 & w3_age<60 & !missing(w3_age) & w3_age!=999 & w3_inhh==1
			bys hhid: egen w3_hh_12to60=total(temp)
			drop temp

		** Marital status
			gen w3_married=(hh_s1q08==2 | hh_s1q08==3) if !missing(hh_s1q08)
			gen w3_married_monog=(hh_s1q08==2) if !missing(hh_s1q08)
			gen w3_married_polyg=(hh_s1q08==3) if !missing(hh_s1q08)

		** Female
			gen w3_female=(hh_s1q03==2) if !missing(hh_s1q03)
			replace w3_female=(hh_s1q04e==2) if !missing(hh_s1q04e)

		** Age of spouse
			sum indiv
			forvalues x=1/`r(max)' {
				gen age_person`x'_temp=w3_age if indiv==`x' & !missing(w3_age)
				bys hhid: egen age_person`x'=max(age_person`x'_temp)
				drop age_person`x'_temp
			}

		** Average age of others in the household
			sum indiv 
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if indiv==`x'
			}
			egen w3_hh_avgage=rowmean(age_person*)
			
		** Spouse age
			sum indiv
			forvalues x=1/`r(max)' {
				replace age_person`x'=. if hh_s1q10!=`x'
			}
			egen w3_spouse_age=rowmean(age_person*)

		** Age gap
			gen w3_spouse_agegap=w3_age-w3_spouse_age

		** Birthday
			gen w3_birthday=mdy(hh_s1q04g_2,hh_s1q04g_1,hh_s1q04g_3)
			format w3_birthday %td
			
		** Birth year
			gen w3_birthyear=hh_s1q04g_3
			recode w3_birthyear 9999=. 9998=.
			replace w3_birthyear=2015-w3_age if missing(w3_birthyear)
	
	***********
	***********
	
	** Geographic information
	
		gen w3_geo_urban=(rural==2 | rural==3) if !missing(rural)
		
	***********
	***********

	** LABOR

		** Worked for a non-HH member
			egen w3_work_outsideHH_hrs=rowtotal(hh_s4q06 hh_s4q07), mi
			gen w3_work_outsideHH=w3_work_outsideHH_hrs>0 if !missing(w3_work_outsideHH_hrs)
		
		** Worked in agriculture for a HH member
			gen w3_work_agHH_hrs=hh_s4q04
			gen w3_work_agHH=w3_work_agHH_hrs>0 if !missing(w3_work_agHH_hrs)
			
		** Worked in HH business
			gen w3_work_bizHH_hrs=hh_s4q05
			gen w3_work_bizHH=w3_work_bizHH_hrs>0 if !missing(w3_work_bizHH_hrs)

		** Any work in last 7 days (agriculture, for non-HH member, own account/business)
			egen w3_worked_last7days=rowmax(w3_work_outsideHH w3_work_agHH w3_work_bizHH)
			
		** Hours worked in last 7 days
			egen w3_work_hrs=rowtotal(w3_work_outsideHH_hrs w3_work_agHH_hrs w3_work_bizHH_hrs)
			replace w3_work_hrs=. if missing(w3_work_outsideHH_hrs) & missing(w3_work_agHH_hrs) & missing(w3_work_bizHH_hrs)

		** Works in agriculture
			gen w3_work_agri=(hh_s4q11_b==1 | hh_s4q11_b==2 | hh_s4q22_b==1 | hh_s4q22_b==2 | w3_work_agHH==1) if (!missing(hh_s4q11_b) | !missing(hh_s4q11_b) | !missing(w3_work_agHH))
		
	***********
	***********

	** HEALTH
		
		** Any illness or injury during the last 4 weeks
			gen w3_ill_inj=(hh_s3q03==1) if !missing(hh_s3q03)

		** Had to stop usual activity in the past 4 weeks
			gen w3_ill_inj_stopactivity=(hh_s3q05>0) if !missing(hh_s3q05)
			replace w3_ill_inj_stopactivity=0 if w3_ill_inj==0

	***********
	***********


	** DISABILITIES

		** Difficulty seeing
			tab1 hh_s3q12, nol
			tab1 hh_s3q12
			gen w3_diff_seei=1 if inlist(hh_s3q12, 2, 3, 4) 
			replace w3_diff_seei=0 if inlist(hh_s3q12, 1)
			replace w3_diff_seei=. if inlist(hh_s3q12, .)
			tab1 w3_diff_seei

		** Difficulty hearing
			tab1 hh_s3q13, nol
			tab1 hh_s3q13
			gen w3_diff_hear=1 if inlist(hh_s3q13, 2, 3, 4) 
			replace w3_diff_hear=0 if inlist(hh_s3q13, 1)
			replace w3_diff_hear=. if inlist(hh_s3q13, .)
			tab1 w3_diff_hear

		** Difficulty walking or climbing stairs	
			tab1 hh_s3q14, nol
			tab1 hh_s3q14
			gen w3_diff_walk_clim=1 if inlist(hh_s3q14, 2, 3, 4) 
			replace w3_diff_walk_clim=0 if inlist(hh_s3q14, 1)
			replace w3_diff_walk_clim=. if inlist(hh_s3q14, .)
			tab1 w3_diff_walk_clim

		** Difficulty remembering or concentrating
			tab1 hh_s3q15, nol
			tab1 hh_s3q15
			gen w3_diff_reme=1 if inlist(hh_s3q15, 2, 3, 4) 
			replace w3_diff_reme=0 if inlist(hh_s3q15,1)
			replace w3_diff_reme=. if inlist(hh_s3q15, .)
			tab1 w3_diff_reme

		** Difficulty with self-care
			tab1 hh_s3q16, nol
			tab1 hh_s3q16
			gen w3_diff_self_care=1 if inlist(hh_s3q16, 2, 3, 4)
			replace w3_diff_self_care=0 if inlist(hh_s3q16, 1)
			replace w3_diff_self_care=. if inlist(hh_s3q16, .)
			tab1 w3_diff_self_care

		** Difficulty communicating
			tab1 hh_s3q17, nol
			tab1 hh_s3q17
			gen w3_diff_comm=1 if inlist(hh_s3q17, 2, 3, 4) 
			replace w3_diff_comm=0 if inlist(hh_s3q17, 1)
			replace w3_diff_comm=. if inlist(hh_s3q17, .)
			tab1 w3_diff_comm
			
	***********
	***********
	
	** SAVE
	
		keep hhid indiv w3*
		order hhid indiv w3*
		save "$dir/data/ETH_w3_individual.dta", replace
